package com.hujf.netty.tcp.protocoltcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author Hujf
 * @title: MessageEncoder
 * @date 2021/2/6 0006下午 3:45
 * @description: TODO
 */
public class MessageEncoder extends MessageToByteEncoder<MessageProtocol> {
    @Override
    protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) throws Exception {
        System.out.println("编码被调用");

        out.writeInt(msg.getLen());
        out.writeBytes(msg.getContent());
    }
}
